home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d998.lha / TeXPrt / source / Process.c < prev    next >
C/C++ Source or Header  |  1994-04-05  |  12KB  |  248 lines

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *  Filename : Process.c                                                   *
  4.  *                                                                         *
  5.  *  Description : Processing routines for user inputs.                     *
  6.  *                                                                         *
  7.  ***************************************************************************
  8.  *                                                                         *
  9.  *                         Modification History                            *
  10.  *                                                                         *
  11.  *  Date      Author       Comments                                        *
  12.  * ----------------------------------------------------------------------  *
  13.  * 10.6.93    R.Bödi       Created.                                        *
  14.  * 21.2.94    R.Bödi       Changed event loop for MUI.                     *
  15.  *                                                                         *
  16.  ***************************************************************************
  17.  *                                                                         *
  18.  * Copyright © 1993 Richard Bödi,  All rights reserved.                    *
  19.  *                                                                         *
  20.  ***************************************************************************/
  21.  
  22. /*----------------------------- INCLUDES ----------------------------------*/
  23.  
  24. #include "TeXPrt.h"
  25. #include "TexPrt_protos.h"
  26. #include "TexPrt_globals.h"
  27.  
  28. /*-------------------------- GLOBAL DATA ----------------------------------*/
  29.  
  30. static struct FileRequester   *FileRequester;
  31. static char                   *SaveAsTxt = "Save spec file as";
  32.  
  33. struct Status           Status = { FALSE, FALSE, FALSE };
  34.  
  35. /*------------------------------- CODE ------------------------------------*/
  36.  
  37.  
  38. /***************************************************************************
  39.  *                                                                         *
  40.  *  Function name : ProcessIDCMP                                           *
  41.  *                                                                         *
  42.  *  Description : Tests window's IDCMP port for incoming messages.         *
  43.  *                This function returns if the window close gaget or the   *
  44.  *                CANCEL gadget was activated.                             *
  45.  *                                                                         *
  46.  ***************************************************************************
  47.  *                                                                         *
  48.  *  Synopsis : ProcessIDCMP (Structures, NonMUISignals)                    *
  49.  *                                                                         *
  50.  *  Parameters :                                                           *
  51.  *       (struct StructPointers *) Structures:                             *
  52.  *          Contains pointers to various data pools.                       *
  53.  *       (long) NonMUISignals:                                             *
  54.  *          Contains signal bits that doesn't belong to the MUI.           *
  55.  *                                                                         *
  56.  *  Return value : None                                                    *
  57.  *                                                                         *
  58.  ***************************************************************************/
  59.  
  60. void ProcessIDCMP (struct StructPointers *Structures, long NonMUISignals)
  61.  
  62. {
  63. long              SignalArrived = 0, MUISignal = 0;
  64. USHORT            Line;
  65. ULONG             Action;
  66. char              Buffer[FMSIZE];
  67. struct AppMessage *AMsg;
  68. struct TagItem    FReqTags[4];
  69.  
  70.  
  71. while (!Status.Exit)
  72.    {
  73.    switch (Action = DoMethod (Structures->MUIPointers->app, MUIM_Application_Input, &MUISignal))
  74.       {
  75.       case ID_SAVE:
  76.          if (!SaveDriverSpec (Structures->AvailDrivers->DriverFiles + Structures->DriverNumber * NAMELENGTH,
  77.                               Structures->TeXDriver, Structures->RawSettings, Structures->DefaultSettings,
  78.                               Structures->MUIPointers))
  79.             EasyRequest (Structures->MUIPointers->MainWindow, &SaveErrorReq, &IDCMPFlag,
  80.                          Structures->AvailDrivers->DriverFiles + Structures->DriverNumber * NAMELENGTH);
  81.          break;
  82.  
  83.       case ID_SAVEAS:
  84.          FReqTags[0].ti_Tag  = ASL_File;
  85.          FReqTags[0].ti_Data = (ULONG)Structures->AvailDrivers->DriverFiles + Structures->DriverNumber * NAMELENGTH;
  86.          FReqTags[1].ti_Tag  = ASL_Dir;
  87.          FReqTags[1].ti_Data = (ULONG)DriverDrawer;
  88.          FReqTags[2].ti_Tag  = ASL_Hail;
  89.          FReqTags[2].ti_Data = (ULONG)SaveAsTxt;
  90.          FReqTags[3].ti_Tag  = TAG_DONE;
  91.  
  92.          if (FileRequester = MUI_AllocAslRequest (ASL_FileRequest, FReqTags))
  93.             if (MUI_AslRequest (FileRequester, NULL))
  94.                {
  95.                if (!SaveDriverSpec (FileRequester->rf_File, Structures->TeXDriver, Structures->RawSettings,
  96.                                     Structures->DefaultSettings, Structures->MUIPointers))
  97.                   EasyRequest (Structures->MUIPointers->MainWindow, &SaveErrorReq, &IDCMPFlag, FileRequester->rf_File);
  98.                MUI_FreeAslRequest (FileRequester);
  99.                }
  100.          break;
  101.  
  102.       case ID_ABOUT:
  103.           EasyRequest (Structures->MUIPointers->MainWindow, &AboutReq, &IDCMPFlag, &Version[6]);
  104.          break;
  105.  
  106.       case ID_PRINT:
  107.          if (Structures->ARexxAvailable)
  108.             system (RexxPrintMacro);
  109.          else
  110.             CallPrinterDriver (Structures, FALSE);
  111.          break;
  112.  
  113.       case ID_PRINTAREXX:
  114.          CallPrinterDriver (Structures, FALSE);
  115.          break;
  116.  
  117.       case ID_FROM_PAGE:
  118.       case ID_TO_PAGE:
  119.          SetAttrs (Structures->MUIPointers->RAD_FromTo, MUIA_Radio_Active, FROMTO, TAG_DONE);
  120.          break;
  121.  
  122.       case ID_TOFRONT:
  123.          DoMethod (Structures->MUIPointers->MainWindow, MUIM_Window_ToFront, TRUE);
  124.          break;
  125.  
  126.       case ID_SCREENTOFRONT:
  127.          DoMethod (Structures->MUIPointers->MainWindow, MUIM_Window_ScreenToFront, TRUE);
  128.          break;
  129.  
  130.       case ID_TOBACK:
  131.          DoMethod (Structures->MUIPointers->MainWindow, MUIM_Window_ToBack, TRUE);
  132.          break;
  133.  
  134.       case ID_SCREENTOBACK:
  135.          DoMethod (Structures->MUIPointers->MainWindow, MUIM_Window_ScreenToBack, TRUE);
  136.          break;
  137.  
  138.       case ID_QUIT:
  139.          Status.Exit = TRUE;
  140.          break;
  141.  
  142.       case MUIV_Application_ReturnID_Quit:
  143.          Status.Exit = Status.ARexx = TRUE;
  144.          break;
  145.       }
  146.  
  147.    if ((Action >= ID_DRIVER) && (Action <= (ID_DRIVER + Structures->AvailDrivers->NoOfDrivers)))
  148.       {
  149.       if (Line = LoadDriverSpec (Structures, Action - ID_DRIVER))
  150.          EasyRequest (Structures->MUIPointers->MainWindow, &LoadErrorReq, &IDCMPFlag,
  151.                       Structures->AvailDrivers->DriverFiles + (Action - ID_DRIVER) * NAMELENGTH, Line);
  152.       else
  153.          UpdateGUI (Structures->MUIPointers, Structures->DefaultSettings, Structures->ParsedSettings);
  154.       }
  155.  
  156.    if (SignalArrived & NonMUISignals)
  157.       while (AMsg = (struct AppMessage *)GetMsg (AppMsgPort))
  158.          {
  159.          Status.ARexx = FALSE;
  160.  
  161.          switch (AMsg->am_Type)
  162.             {
  163.             case MTYPE_APPICON:
  164.                if (AMsg->am_NumArgs == 0)
  165.                   Status.Exit = !EasyRequest (NULL, &AppIconReq, &IDCMPFlag, NULL);
  166.                else
  167.                   {
  168.                   NameFromLock (AMsg->am_ArgList->wa_Lock, Buffer, sizeof (Buffer));
  169.                   strmfp (Args.ArgStr[KW_FILE], Buffer, AMsg->am_ArgList->wa_Name);
  170.                   SetAttrs (Structures->MUIPointers->STR_DVIFile, MUIA_String_Contents, Args.ArgStr[KW_FILE], TAG_DONE);
  171.                   }
  172.                break;
  173.             }
  174.  
  175.          ReplyMsg ((struct Message *)AMsg);
  176.          }
  177.  
  178.    if (Status.Exit & !Status.ARexx)
  179.       Status.Exit = EasyRequest (Structures->MUIPointers->MainWindow, &QuitReq, &IDCMPFlag, NULL);
  180.    else
  181.       if ((!Status.Exit) && (MUISignal)) SignalArrived = Wait (MUISignal | NonMUISignals);
  182.  
  183.    Status.ARexx = FALSE;
  184.    }
  185. }
  186.  
  187.  
  188. /***************************************************************************
  189.  *                                                                         *
  190.  *  Function name : UpdateGUI                                              *
  191.  *                                                                         *
  192.  *  Description : Updates the GUI with the corresponding values of the     *
  193.  *                TeXDriver structure.                                     *
  194.  *                                                                         *
  195.  ***************************************************************************
  196.  *                                                                         *
  197.  *  Synopsis : UpdateGUI (Pointers, Default)                               *
  198.  *                                                                         *
  199.  *  Parameters :                                                           *
  200.  *    (struct MUIPointers *) Pointers:                                     *
  201.  *       A structure consisting of APTRs to MUI elements.                  *
  202.  *    (struct DefaultSettings *) Default:                                  *
  203.  *       Contains the settings for updating the GUI.                       *
  204.  *    (struct ParsedSettings *) Parsed:                                    *
  205.  *       Contains the aprsed command line parameters.                      *
  206.  *                                                                         *
  207.  *  Return value : None                                                    *
  208.  *                                                                         *
  209.  ***************************************************************************/
  210.  
  211. void UpdateGUI (struct MUIPointers *Pointers, struct DefaultSettings *Default, struct ParsedSettings *Parsed)
  212.  
  213. {
  214. int   OptionCount;
  215. BOOL  Disabled;
  216.  
  217. SetAttrs (Pointers->STR_OutFile, MUIA_String_Contents, Default->DeviceName, TAG_DONE);
  218. SetAttrs (Pointers->STR_Copies, MUIA_String_Integer, Default->Copies, TAG_DONE);
  219. SetAttrs (Pointers->STR_X, MUIA_String_Integer, Default->HOffset, TAG_DONE);
  220. SetAttrs (Pointers->STR_Y, MUIA_String_Integer, Default->VOffset, TAG_DONE);
  221. SetAttrs (Pointers->RAD_FromTo, MUIA_Radio_Active, Default->PageSel, TAG_DONE);
  222. SetAttrs (Pointers->RAD_OddEven, MUIA_Radio_Active, Default->PageType, TAG_DONE);
  223. SetAttrs (Pointers->RAD_Orientation, MUIA_Radio_Active, Default->Orientation, TAG_DONE);
  224. SetAttrs (Pointers->TXT_X, MUIA_Text_Contents, Parsed->HOffsetTxt, TAG_DONE);
  225. SetAttrs (Pointers->TXT_Y, MUIA_Text_Contents, Parsed->VOffsetTxt, TAG_DONE);
  226.  
  227. Disabled = Parsed->Device[0] == ' ' ? TRUE : FALSE;
  228. SetAttrs (Pointers->IMG_Out, MUIA_Disabled, Disabled, TAG_DONE);
  229. Disabled = Parsed->OddPages[0] == ' ' ? TRUE : FALSE;
  230. SetAttrs (Pointers->RAD_OddEven, MUIA_Disabled, Disabled, TAG_DONE);
  231. Disabled = ((Parsed->Portrait[0] = ' ') && (Parsed->LandScape[0] == ' ')) ? TRUE : FALSE;
  232. SetAttrs (Pointers->RAD_Orientation, MUIA_Disabled, Disabled, TAG_DONE);
  233. Disabled = Parsed->HOffset[0] == ' ' ? TRUE : FALSE;
  234. SetAttrs (Pointers->STR_X, MUIA_Disabled, Disabled, TAG_DONE);
  235. Disabled = Parsed->VOffset[0] == ' ' ? TRUE : FALSE;
  236. SetAttrs (Pointers->STR_Y, MUIA_Disabled, Disabled, TAG_DONE);
  237.  
  238. for (OptionCount = 0; OptionCount < OPTIONS; OptionCount++)
  239.    {
  240.    SetAttrs (Pointers->CHM_Option[OptionCount], MUIA_Selected, Default->Option[OptionCount], TAG_DONE);
  241.    SetAttrs (Pointers->TXT_Option[OptionCount], MUIA_Text_Contents, Parsed->OptionTxt[OptionCount], TAG_DONE);
  242.    Disabled = Parsed->Option[OptionCount][0] == ' ' ? TRUE : FALSE;
  243.    SetAttrs (Pointers->CHM_Option[OptionCount], MUIA_Disabled, Disabled, TAG_DONE);
  244.    }
  245. }
  246.  
  247. /*---------------------------- END OF FILE --------------------------------*/
  248.